﻿using System;
using System.IO;
using System.Reflection;
using log4net;
using log4net.Config;
using log4net.Repository;

[assembly: XmlConfigurator(Watch = true)]
namespace FrameWork
{
    public static class Log4Help
    {
        private static readonly ILoggerRepository Repository;
        private static readonly object Lockobj = new object();
        static Log4Help()
        {
            if (Repository != null) return;

            lock (Lockobj)
            {
                Repository = LogManager.CreateRepository("NETCoreRepository");
                XmlConfigurator.Configure(Repository, new FileInfo("log4net.config"));
            }
        }

        public static void Debug(string msg)
        {
            var log = LogManager.GetLogger(Repository.Name, MethodBase.GetCurrentMethod().DeclaringType);
            log.Debug(msg);
        }

        public static void Error(string msg)
        {
            var log = LogManager.GetLogger(Repository.Name, MethodBase.GetCurrentMethod().DeclaringType);
            log.Error(msg);
        }
        public static void Error(string msg, Exception exception)
        {
            var log = LogManager.GetLogger(Repository.Name, MethodBase.GetCurrentMethod().DeclaringType);
            log.Error(msg, exception);
        }

        public static void Fatal(string msg)
        {
            var log = LogManager.GetLogger(Repository.Name, MethodBase.GetCurrentMethod().DeclaringType);
            log.Fatal(msg);
        }

        public static void Info(string msg)
        {
            var log = LogManager.GetLogger(Repository.Name, MethodBase.GetCurrentMethod().DeclaringType);
            log.Info(msg);
        }

        public static void Warn(string msg)
        {
            var log = LogManager.GetLogger(Repository.Name, MethodBase.GetCurrentMethod().DeclaringType);
            log.Warn(msg);
        }
    }
}

